package com.youbug.mall.coupon_sms.service.impl;

import com.youbug.mall.coupon_sms.entity.SmsSeckillSkuNotice;
import com.youbug.mall.coupon_sms.mapper.SmsSeckillSkuNoticeMapper;
import com.youbug.mall.coupon_sms.service.ISmsSeckillSkuNoticeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.youbug.mall.coupon_sms.entity.SmsSeckillSkuNotice;
import org.springframework.util.ObjectUtils;
import com.youbug.common.vo.QueryVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.util.StringUtils;
import org.springframework.util.ObjectUtils;

/**
 * <p>
 * 秒杀商品通知订阅 服务实现类
 * </p>
 *
 * @author youbug
 * @since 2024-07-20
 */
@Service
public class SmsSeckillSkuNoticeServiceImpl extends ServiceImpl<SmsSeckillSkuNoticeMapper, SmsSeckillSkuNotice> implements ISmsSeckillSkuNoticeService {

        @Override
        public IPage<SmsSeckillSkuNotice> getSmsSeckillSkuNoticePage(QueryVo<SmsSeckillSkuNotice> queryVo) {

        Page<SmsSeckillSkuNotice> paramPage = new Page<>();

        paramPage.setCurrent(queryVo.getCurrentPage());

        paramPage.setSize(queryVo.getPageSize());

        QueryWrapper<SmsSeckillSkuNotice> wrapper = new QueryWrapper<>();

        SmsSeckillSkuNotice smsSeckillSkuNotice = queryVo.getPayload();

        if(!ObjectUtils.isEmpty(smsSeckillSkuNotice)){
            if(smsSeckillSkuNotice.getId()!=null){
            wrapper.eq("id", smsSeckillSkuNotice.getId());
            }
            if(smsSeckillSkuNotice.getMemberId()!=null){
            wrapper.eq("member_id", smsSeckillSkuNotice.getMemberId());
            }
            if(smsSeckillSkuNotice.getSkuId()!=null){
            wrapper.eq("sku_id", smsSeckillSkuNotice.getSkuId());
            }
            if(smsSeckillSkuNotice.getSessionId()!=null){
            wrapper.eq("session_id", smsSeckillSkuNotice.getSessionId());
            }
            if(!ObjectUtils.isEmpty(smsSeckillSkuNotice.getSubcribeTime())){
                wrapper.gt("subcribe_time", smsSeckillSkuNotice.getSubcribeTime());
            }
            if(!ObjectUtils.isEmpty(smsSeckillSkuNotice.getSendTime())){
                wrapper.gt("send_time", smsSeckillSkuNotice.getSendTime());
            }
        }
        if(!ObjectUtils.isEmpty(queryVo.getStartTime())){
            wrapper.gt("create_time", queryVo.getStartTime());
        }
        if(!ObjectUtils.isEmpty(queryVo.getEndTime())){
            wrapper.lt("create_time", queryVo.getEndTime());
        }
        wrapper.orderByDesc("create_time");

        Page<SmsSeckillSkuNotice> page = this.page(paramPage, wrapper);

        return page;
        }

       /* @Transactional(transactionManager = "transactionManagerXXX", rollbackFor = Exception.class)
        public boolean saveBatch(Collection<SmsSeckillSkuNotice> entityList) {
        return saveBatch(entityList, DEFAULT_BATCH_SIZE);
        }
        */
}
